#include "app_buffer.h"
#include "log/log.h"

int main(int argc, char const *argv[])
{

    unsigned char a = 255;
    int b = a;
    log_debug("b=%d", b);

    Buffer *buffer0 = app_buffer_init(512);

    char data[128];
    for (int i = 0; i < 128; i++)
    {
        data[i] = 'a';
    }
    app_buffer_write(buffer0, data, 128);
    
    char data_buf0[100];
    int data_len0 = app_buffer_read(buffer0, data_buf0, 100);
    log_debug("data_buf: %.*s", data_len0, data_buf0);
    

    // 初始化缓冲区
    Buffer *buffer = app_buffer_init(150);
    
    // 写数据
    app_buffer_write(buffer, "abcde", 5);
    app_buffer_write(buffer, "fghijh", 6);

    // 读取数据1
    char data_buf[100];
    int data_len = app_buffer_read(buffer, data_buf, 100);
    log_debug("data_buf: %.*s", data_len, data_buf);

    // 读取数据2
    char data_buf2[100];
    int data_len2 = app_buffer_read(buffer, data_buf2, 100);
    log_debug("data_buf2: %.*s", data_len2, data_buf2);

    // 读取数据 => 此时是空的，读取会失败
    char data_buf3[100];
    int data_len3 = app_buffer_read(buffer, data_buf3, 100);
    log_debug("data_buf3: %.*s", data_len3, data_buf3);

    // 写过长的数据 => 写会失败
    app_buffer_write(buffer, "aaaaaaabbbbbbbeeeeeee", 20);

    // 销毁缓冲区
    app_buffer_free(buffer);

    return 0;
}
